<?php

class ctrl_wishBuyAccount extends L {

    /**
     * 描述 ：wish买家账号页面展示
     * 作者 ：Zoro.Zhu
    **/
    public function index(){
        $this->view->_pagingHtml = $this->paging();
        $this->view->headTitle = 'wish买家账号';
        $this->display('/html/wishBuyAccount.html');
    }

    /**
     * 描述 : 获取分页
     * 作者 : Zoro.Zhu
     */
    public function &paging($params = array()){
        $sql = model_wishBuyAccount::searchSql($params);
        $config = array( 
            '账号' => array(
                '_attr' => array(
                    'body' => '{`account`}',
                    'sort' => 'account'
                )
            ),
            'Cookie' => '<div style="display: inline-block;overflow: hidden;width: 400px;word-break: keep-all;white-space: nowrap;text-overflow: ellipsis;line-height: 28px;float: left;">{`cookie`}</div>',
            'securedtouch_token' => '{`token`}',
            'x-xsrftoken' => '{`xToken`}',
            '操作时间' => array(
                '_attr' => array(
                    'body' => '{`updDate`}',
                    'sort' => 'updDate'
                )
            ),
            '操作'=> "<button class=\"btn btn-oper btn-danger\" type=\"button\" onclick=\"wishBuyAccountObj.wishBuyAccountUpInfo('{`id`}');\">
                <span class=\"fa fa-plus\"></span>修改
            </button>",
            '_attr' => array(
                "attr" => array (
                    "table" => 'id=wishBuyAccountList class="table table-hover table-condensed table-striped table-scroll jsHoverDetails textC"',
                    "btr" => "align='center' class='of-paging_item_odd tr_{`id`}'",
                ),
                'data' => &$sql,
                'params' => &$params,
                'call' => array($this, 'asCall'),
                'method' => __METHOD__,
                'save' => 'auto',
                'empty' => '查无此数据'
            )
        );
        return $this->_com->paging($config);
    }

    /**
     * 描述 : 整理数据
     * 作者 : Zoro.Zhu
     */
    public function asCall(&$data){
        foreach($data['data'] as &$val){

        }
    }

    /**
     * 描述 : 新增和修改的页面展示
     * 作者 : Zoro.Zhu
     */
    public function wishBuyAccountUpInfo(){
        if(!empty($_REQUEST['id'])) {
            $wishBuyAccount = model_wishBuyAccount::getKeyInfo($_REQUEST['id']);
            if(!empty($wishBuyAccount)){ 
                $this->view->id = $wishBuyAccount[0]['id'];
                $this->view->account = $wishBuyAccount[0]['account'];
                $this->view->cookie = $wishBuyAccount[0]['cookie'];
                $this->view->token = $wishBuyAccount[0]['token'];
                $this->view->xToken = $wishBuyAccount[0]['xToken'];
                $this->view->vsAccount = $wishBuyAccount[0]['vsAccount'];
                $this->view->updDate = $wishBuyAccount[0]['updDate'];
            }
        }
        $this->display('/html/wishBuyAccountUpInfo.html');
    }

    /**
     * 描述 ：新增或修改数据
     * 作者 ：Zoro.Zhu
    **/
    public function wishBuyAccountUpd(){
        //主键为空是新增，否则就是修改
        $_POST = removeBlank($_POST);
        $_POST['vsAccount'] = core_base::getUser('name');
        $_POST['updDate'] = date('Y-m-d H:i:s');
        if(empty($_POST['id'])){
            $result = model_wishBuyAccount::insertSql($_POST);
        }else{
            $result = model_wishBuyAccount::updateSql($_POST);
        }
        if($result > 0){
            return array('state' => 200, 'info' => '操作成功');
        }else{
            return array('state' => 301, 'info' => '操作无效');
        }
    }

    /**
     * 描述 ：按条件导出数据
     * 作者 ：Zoro.Zhu
    **/
    public function exportCsv(){
        $sql = model_wishBuyAccount::searchSql(array('search' => $_GET));
        $data = L::sql($sql);
        of_base_com_csv::download('导出数据' . time());                     //导出数据的文件名
        of_base_com_csv::download(array('自增ID','账号','Cookie','securedtouch_token','x-xsrftoken','操作时间',));
        foreach ($data as $row){
            of_base_com_csv::download(array($row['id'],$row['account'],$row['cookie'],$row['token'],$row['xToken'],$row['updDate'],));
        }
    }

}
return true;